package com.qs.education.controller;

import org.apache.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.qs.education.bean.api.PageBean;
import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.entity.EducationSMS;
import com.qs.education.service.ISMSService;

/**
 * @class SMSController
 * @author Jason
 * @description
 * @date Nov 16, 2018 10:37:35 AM
 */
@Controller
public class SMSController {

	@Autowired
	private ISMSService iSMSService;
	
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @Description 查询所有SMS(带条件)
	 * @author Jason
	 * @date Nov 16, 2018
	 * @param sms
	 * @return
	 */
	@RequiresPermissions(value={"user:view"})
	@RequestMapping("/getSMS")
	public ModelAndView getSMS(EducationSMS sms,
			@RequestParam(defaultValue="1",value="currentPage") Integer currentPage,
			@RequestParam(defaultValue="10",value="pageSize") Integer pageSize){
		
		log.info("后台管理-->查询所有SMS");
		ModelAndView mv=new ModelAndView("sms/list");
		PageBean smsPageBean =  iSMSService.getSMSList(sms,currentPage,pageSize);
		mv.addObject("smsPageBean", smsPageBean);
		mv.addObject("sms", sms);
		
		return mv;
	}
	
	/**
	 * @Description 删除SMS
	 * @author Jason
	 * @date Nov 19, 2018
	 * @param Id
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@RequiresPermissions(value={"user:delete"})
	@RequestMapping("/deleteSMS")
	public ModelAndView deleteSMSById(EducationSMS sms,
			@RequestParam(defaultValue="1",value="currentPage") Integer currentPage,
			@RequestParam(defaultValue="10",value="pageSize") Integer pageSize,
			RedirectAttributes attr){
		
		log.info("后台管理-->删除SMS");
		ModelAndView mv=new ModelAndView("forward:/getSMS");
		attr.addFlashAttribute("currentPage", currentPage);
		attr.addFlashAttribute("pageSize", pageSize);
		ResponseBean response =  iSMSService.deleteSMSById(sms.getId());
		mv.addObject("sms", sms);
		
		return mv;
	}
	
	
}
